
package com.shop.cloud.mall.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.OrderProfitSharing;
import com.shop.cloud.mall.admin.service.OrderProfitSharingService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 订单分账
 *
 * @author
 * @date 2023-05-11 11:43:49
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/orderprofitsharing")
@Tag(description = "orderprofitsharing", name = "订单分账管理")
public class OrderProfitSharingController {

    private final OrderProfitSharingService orderProfitSharingService;

    /**
     * 订单分账分页列表
     * @param page 分页对象
     * @param orderProfitSharing 订单分账
     * @return
     */
    @Operation(summary = "订单分账分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('mall:orderprofitsharing:index')")
    public R getPage(Page page, OrderProfitSharing orderProfitSharing) {
        return R.ok(orderProfitSharingService.page(page, Wrappers.query(orderProfitSharing)));
    }

    /**
     * 订单分账查询
     * @param id
     * @return R
     */
    @Operation(summary = "订单分账查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:orderprofitsharing:get')")
    public R getById(@PathVariable("id") String id) {
        return R.ok(orderProfitSharingService.getById(id));
    }

    /**
     * 订单分账新增
     * @param orderProfitSharing 订单分账
     * @return R
     */
    @Operation(summary = "订单分账新增")
    @SysLog("新增订单分账")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('mall:orderprofitsharing:add')")
    public R save(@RequestBody OrderProfitSharing orderProfitSharing) {
        return R.ok(orderProfitSharingService.save(orderProfitSharing));
    }

    /**
     * 订单分账修改
     * @param orderProfitSharing 订单分账
     * @return R
     */
    @Operation(summary = "订单分账修改")
    @SysLog("修改订单分账")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:orderprofitsharing:edit')")
    public R updateById(@RequestBody OrderProfitSharing orderProfitSharing) {
        return R.ok(orderProfitSharingService.updateById(orderProfitSharing));
    }

    /**
     * 订单分账删除
     * @param id
     * @return R
     */
    @Operation(summary = "订单分账删除")
    @SysLog("删除订单分账")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('mall:orderprofitsharing:del')")
    public R removeById(@PathVariable String id) {
        return R.ok(orderProfitSharingService.removeById(id));
    }

}
